/* From tcptraceroute, convert a numeric IP address to a string */
#include "PubDefine.h"
#include<stdlib.h>

u_long iptoul(const ip_address ipaddress)
{
	u_long d = ipaddress.byte1 << 24 | ipaddress.byte2 << 16 | ipaddress.byte3 << 8 | ipaddress.byte4 ;
	return d;
}
void Makehashkey(const nodedata* node,char* out)
{
	unsigned long ipsrc=iptoul(node->srcip)+node->sport;
	unsigned long ipdst=iptoul(node->dstip)+node->dport;
	sprintf(out,"%d",abs(ipsrc+ipdst));
	return;
}
char * iptos(u_long in)
{
    static char output[IPTOSBUFFERS][3*4+3+1];
    static short which;
    u_char *p;

    p = (u_char *)&in;
    which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
    sprintf(output[which], "%d.%d.%d.%d", p[3], p[2], p[1], p[0]);
    return output[which];
}
void getprotoname(u_char proto,char* pname)
{
	switch (proto)
	{
	case IPPROTO_IP:
	     strcpy(pname , "IP");               /* dummy for IP */
	     break;
	case IPPROTO_ICMP:
	     strcpy(pname , "ICMP");   /* control message protocol */
	     break;
	case IPPROTO_IGMP:
	     strcpy(pname , "IGMP");
	     break;             /* internet group management protocol */
#ifndef WIN32
	case IPPROTO_EGP:
	    strcpy(pname , "EGP");
	    break;               /* gateway^2 (deprecated) */
#endif	    
	case IPPROTO_TCP:
	    strcpy(pname , "TCP");
	    break;               /* tcp */
	case IPPROTO_PUP:
	    strcpy(pname , "PUP");
	    break;              /* pup */
	case IPPROTO_UDP:
	    strcpy(pname , "UDP");
	    break;              /* user datagram protocol */
	case IPPROTO_IDP:
	    strcpy(pname , "IDP");
	    break;              /* xns idp */
#ifndef WIN32
	case IPPROTO_IPV6:
	    strcpy(pname , "IPV6");
	    break;              /* IPv6 */
#endif
	case 55 :   //ARP
	     strcpy(pname , "ARP");
	     break;
	default:
	    sprintf(pname , "UNKNOW:%d",proto);
	    break;
}

}
